fix: enforce tenant data isolation and centralize auth#13
Merged
Conversation
The Prisma 7 pg adapter breaks AsyncLocalStorage context after awaited queries. enterWith() called inside verifyRole/verifySession does not propagate back to the caller across the await boundary. - Add restoreCongregationContext() helper to db.server.ts - Call it in all 76 route loaders/actions after verifySession/verifyRole and before the first db or service function call - Covers both direct db usage and indirect usage via service functions
Replace the fragile 3-step pattern (verifySession + verifyRole + restoreCongregationContext) across 83 route files with a single authenticateAndAuthorize() call that handles everything internally. - Create auth.server.ts with authenticateAndAuthorize(request, roles) that combines auth, role checks (via Promise.all), and ALS restore - Return a can(Role) function for cleaner permission checks - Add module-level fallback in db extension for concurrent loaders where React Router runs parallel loaders that break each other's ALS - Translate all French code comments to English - Remove direct verifySession/verifyRole/restoreCongregationContext imports from all route files
c5a7182 to
ed983af
Compare
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/congregation-not-foundfor unknown subdomainsAsyncLocalStorageafter awaited queries, causing the scopeddbclient to silently return unscoped data. The extension now throws on missing context (fail-safe) and re-enters context after each queryauthenticateAndAuthorize()wrapper: replaces the fragile 3-step pattern (verifySession+verifyRole+restoreCongregationContext) across 83 route files with a single function call. Returns acan(Role)function for cleaner permission checks. Role checks run viaPromise.all(faster than sequential)dbextension handles cases where React Router runs parallel loaders that break each other's ALS contextBuilds on #11 which handled session/login tenant validation.
Test plan
MULTI_TENANTunset) → no behavioral changepnpm test:unit— 321 tests passpnpm test:typecheck— cleanpnpm test:lint— clean